package controleurs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import modeles.Parametres;

public class ControleConnexion {
	private static Connection connexionStatic;
	
	static{
		try{
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			connexionStatic = (Connection)DriverManager.getConnection(Parametres.getUrl());
		}catch(ClassNotFoundException e){
			System.out.println("Impossible de charger le pilote : " + e.getMessage());
		}catch(SQLException e){
			System.out.println("Impossible de se connecter : " + e.getMessage());
		}
	}
	
	public static boolean isConnected(){
		return (connexionStatic != null)?true:false;
	}
	public static Connection getConnexion(){
		return connexionStatic;
	}
	
	public static void fermerSession(){
		if(connexionStatic != null){
			try{
				connexionStatic.close();
				connexionStatic = null;
			}catch(SQLException e){
				System.out.println("Impossible de fermer la connexion : " + e.getMessage());
			}
		}
	}
	
	

}
